package com.scuec.tourismwebsite.controller;

import com.scuec.tourismwebsite.entity.PostFavorite;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.scuec.tourismwebsite.service.PostFavoriteService;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("tour/v1")
public class PostFavoriteController {
    @Autowired
    private PostFavoriteService postFavoriteService;

    @GetMapping("favorite")
    public List<PostFavorite> selectPostFavoriteById(@RequestParam("user_id") int user_id, @RequestParam("post_id") int post_id) {
        return postFavoriteService.selectPostFavoriteById(user_id, post_id);
    }

    @PostMapping("favorite/{user_id}/{post_id}")
    public int insertPostFavorite(@PathVariable("user_id") int user_id, @PathVariable("post_id") int post_id) {
        return postFavoriteService.insertPostFavorite(user_id, post_id);
    }

    @DeleteMapping("favorite/{user_id}/{post_id}")
    public int deletePostFavorite(@PathVariable("user_id") int user_id,@PathVariable("post_id") int post_id){
        return postFavoriteService.deletePostFavorite(user_id, post_id);
    }

    @GetMapping("favorites/{user_id}")
    public List<PostFavorite> getUserFavorites(@PathVariable("user_id") Integer user_id) {
        return postFavoriteService.getUserFavorites(user_id);
    }
}
